package com.guoguo.cloudmusic.ui.home.find

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import com.guoguo.cloudmusic.logic.Repository
import com.guoguo.cloudmusic.logic.model.SearchSongs
import com.guoguo.cloudmusic.logic.model.UserPlayList

/**
 * @author GuoGuo
 * @date 2021/12/21
 */
class FindViewModel : ViewModel() {
    //获取播放歌单
    private val userUID = MutableLiveData<String>()
    val playList = ArrayList<UserPlayList.Playlist>()
    val playListLiveData = Transformations.switchMap(userUID) {
        Repository.getPlayList(it)
    }

    fun getPlayList(data: String) {
        playList.clear()
        userUID.value = data
    }
    //搜索功能
    private val keyword = MutableLiveData<String>()
    val keyWordLiveData = Transformations.switchMap(keyword) {
        Repository.search(it)
    }
    fun  searchKeyword(data: String){
        keyword.value = data
    }
    val getSearchKey: String?
        get() = keyword.value
}